<?php

Raise::load('core.RaiseObject');
Raise::load('core.RaiseStack');
Raise::load('core.RaiseCollection');
Raise::load('core.RaiseStackFrame');

/**
 * RaiseStackTrace class
 * helps to retrieve the stack trace
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.Reflection
 * @since 1.2
 */
class RaiseStackTrace extends RaiseObject {

    /**
     * Get the current frame
     * @return RaiseStackFrame
     */
    public function frame() {
        $trace = debug_backtrace();
        array_shift($trace);
        $a = array_shift($trace);

        $frame = new RaiseStackFrame();
        //$frame->args()->append($a['args']);
        //$frame->className($a['class']);
        $frame->file($a['file']);
        $frame->line($a['line']);
        //$frame->name($a['function']);
        //$frame->object($a['object']);
        //$frame->type($a['type']);

        return $frame;
    }

    /**
     * Get the entire frame stack
     * @return RaiseStack
     */
    public function frames() {
        $trace = debug_backtrace();
        array_shift($trace);
        $stack = new RaiseStack();

        foreach ($trace as $a) {
            $frame = new RaiseStackFrame();
            $frame->args()->append($a['args']);
            $frame->className($a['class']);
            $frame->file($a['file']);
            $frame->line($a['line']);
            $frame->name($a['function']);
            $frame->object($a['object']);
            $frame->type($a['type']);
            $stack->push($frame);
        }

        return $stack;
    }

}